<?php

namespace business\elasticsearch\models;

use yii\elasticsearch\ActiveRecord;

class BigDataSupplierModel extends ActiveRecord
{

    public function attributes()
    {
        return [
            'companySupplierId',
            'customProperty',
            'supplierId',
            'supplierName',
            'supplierIntroduce',
            'registCapi',
            'supplierTag',
            'supplierProvinceCode',
            'supplierProvinceName',
            'supplierCityCode',
            'supplierCityName',
            'supplierLocationName',
            'supplierBusinessCode1',
            'supplierBusinessName1',
            'supplierBusinessCode2',
            'supplierBusinessName2',
            'supplierBusinessCode3',
            'supplierBusinessName3',
            'supplierBusinessName',
            'update_timestamp',
            'supplierProjectCase',
            'supplierQualificationName',
            'supplierQualificationCode',
            'matchedProjectName',
            'matchedProjectNumber',
            'topStrategySupplier',
            'topDeveloper',
            'topBusinessArea',
            'boardList',
            'pointBusiness',
            'pointQualifications',
            'pointCase',
            'hasProduct',
            'pointContact',
            'pointCooperative',
            'hasRegulatory',
            'hasRichcase',
            'boardCout',
            'supplierProjectCaseNumber',
            'cooperationDevelopersNumber',
            'qualificationNumber',
            'memberNumber',
            'linkNumber',
            'registCapiRmb',
            'isPreciseMatch',
            'supplierScope',
            'matchedTopDeveloper',
            'matchedTopDeveloperNumber',
            'matchedTopBusinessArea',
            'matchedTopBusinessAreaNumber',
            'indexCreatedTime',
        ];
    }


    /**
     * @desc 查询
     * @param array $query
     * @return array|ActiveRecord|null
     */
    public static function getOne($query = [])
    {
        $es_query = self::find();

        // 匹配查询
        if ($query && !empty($query)) {
            $es_query->query($query);
        }
        // 分组
        return $es_query->one();
    }

    /**
     * 通过供应商id查询一条信息
     * @param $supplierId
     * @return array|ActiveRecord|null
     */
    public static function getOneBySupplierId($supplierId)
    {
        return self::getOne([
            'term' => [
                'supplierId.keyword' => $supplierId
            ]
        ]);
    }

    public static function index()
    {
        //return value is index alias . raw name is b2b_company.supplier
        return 'big_data_supplier';
    }

    public static function type()
    {
        return 'supplier';
    }
}
